package cc.aiee.zalopay.core.pojo;

import cc.aiee.zalopay.config.ZalopayConfig;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import vn.zalopay.crypto.HMACUtil;

@Data
public class ZalopayBaseModel {

	protected String app_id;

	protected String mac;

	public void setAppId(ZalopayConfig config) {
		if (StrUtil.isBlank(app_id)) {
			app_id = config.getAppId();
		}
	}

	public void setMac(String key1, String appId, String... filed) {
		String symbol = "|";
		StringBuilder sbl = new StringBuilder(appId);
		if (filed != null) {
			for (String f : filed) {
				sbl.append(symbol);
				sbl.append(f);
			}
		}
		mac = HMACUtil.HMacHexStringEncode(HMACUtil.HMACSHA256, key1, sbl.toString());
	}
}
